//
//  NewFeatureViewController.m
//  OC-LBWeibo
//
//  Created by 李博 on 15/7/9.
//  Copyright © 2015年 libo. All rights reserved.
//

#import "NewFeatureViewController.h"
#import "NewFeatureCell.h"

#define imageCount 4

@interface NewFeatureViewController ()

@end

@implementation NewFeatureViewController

static NSString * const reuseIdentifier = @"Cell";

- (instancetype)init {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = [UIScreen mainScreen].bounds.size;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    
    return [super initWithCollectionViewLayout:layout];
}


- (void)viewDidLoad {
    [super viewDidLoad];

    // 注册可重用cell
    [self.collectionView registerClass:[NewFeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
    self.collectionView.bounces = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.pagingEnabled = YES;
    
}


#pragma mark <UICollectionViewDataSource>

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return imageCount;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NewFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    cell.imageIndex = (int)indexPath.item;
    
    return cell;
}

- (void)collectionView:(nonnull UICollectionView *)collectionView didEndDisplayingCell:(nonnull UICollectionViewCell *)cell forItemAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    //获取当前显示cell
    NSIndexPath *path = self.collectionView.indexPathsForVisibleItems.lastObject;
    if (path.item == imageCount - 1) {
        NewFeatureCell *cell = (NewFeatureCell *)[self.collectionView cellForItemAtIndexPath:path];
        
        [cell showStartButtton];
    }
}



@end

